<?php

namespace app\controller\news;

use app\common\business\news\NewsBus;
use app\controller\ApiController;

class News extends ApiController
{
    /**
     * 资讯列表
     * @return \support\Response
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function newsList()
    {
        $type = request()->param('type', 0, 'intval');
        $page = request()->param('page', 1, 'intval');
        $num = self::paramNum();
        $lang = request()->header('Device-lang', 'zh_CN');

        $res = NewsBus::newsListBus($type, $lang, $page, $num);

        return self::success($res);
    }

    /**
     * 资讯详情
     * @return \support\Response
     */
    public function newDetail()
    {
        $newId = request()->param('new_id', 0, 'intval');
        if ($newId == 0) {
            return self::error(trans('Parameter error'));
        }
        $res = NewsBus::newDetail($newId);
        return self::success($res);
    }
}
